#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n; cin >> n;
	vector<int> a(n + 1), b(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) cin >> b[i];
	int p, q; cin >> p >> q;
	int mi = 1000000, f = 0, pos = -1, t = 0;
	for (int i = 1; i <= n; i++) {
		if (a[i] == 0) {
			f = 1;
			if (abs(i - q) <= mi) {
				mi = min(mi, abs(i - q));
				pos = i;
				t = 1;
			}
		}
		if (b[i] == 0) {
			f = 1;
			if (abs(i - q) <= mi) {
				mi = min(mi, abs(i - q));
				pos = i;
				t = 2;
			}
		}
	}

	if (!f) cout << -1 << endl;
	else {
		if (a[pos] == 0 && b[pos] == 0) {
			cout << 0 << " " << abs(pos - q) << endl;
		}
		else if (t == 1) {
			cout << 0 << " " << abs(pos - q) << endl;
		}
		else if (t == 2) {
			cout << 1 << " " << abs(pos - q) << endl;
		}
	}
	return 0;
}